<template>
  <div class="right-project-item-box">
    <div class="right-project-item right-project-item-folder">
      <img
        src="https://image.xuexiwangzhe.com/FqNY9-eLDVFFpDdMhC9lDcmOW-GA"
        class="right-project-item-folder-top-img"
        v-if="!batch"
      />
      <img
        src="https://image.xuexiwangzhe.com/FjLnYwXxmsWE9MmLGIs5dH93Y8pr"
        class="right-project-item-folder-top-img right-project-item-folder-top-batch-img"
        v-else
      />
      <div class="right-project-item-folder-main">
        <div class="right-project-item-top right-project-item-folder-main-top">
          <div class="right-project-item-title right-project-item-folder-title">
            {{ data.name }}
          </div>
          <div class="right-project-item-menu-box">
            <img
              src="https://image.xuexiwangzhe.com/FouYcpWD0njmKlGTrr7lLpWUdzdO"
              class="right-project-item-share-img"
              @click="menuModalShow = true"
            />
            <div
              class="right-project-item-menu-modal"
              v-click-outside="closeMenuModal"
              v-if="menuModalShow"
            >
              <div v-if="navActived !== 'recycle'">
                <div
                  class="right-project-item-menu-modal-item"
                  @mouseover="moveTreeMenu = true"
                  @mouseleave="moveTreeMenu = false"
                >
                  <div class="right-project-item-menu-modal-item-left">
                    <img
                      src="https://image.xuexiwangzhe.com/Fv1acxz_u39Rnt2YTNEM3UHZsVLX"
                      class="right-project-item-menu-modal-item-left-img"
                    />
                    <img
                      src="https://image.xuexiwangzhe.com/Fq0qU2pDNqDEdMHCkxxuO3JPfCC_"
                      class="right-project-item-menu-modal-item-left-img-actived"
                    />
                    <div>移动到</div>
                  </div>
                  <img
                    src="https://image.xuexiwangzhe.com/FlPspKXYPYyP4rPiVoTfgtizauvI"
                    class="right-project-item-menu-modal-item-right-img"
                  />
                  <img
                    src="https://image.xuexiwangzhe.com/Fr_uD5OQu6RGAy8LV3UZ5-n-jGp4"
                    class="right-project-item-menu-modal-item-right-img-actived"
                  />
                  <move-folder-tree-menu
                    v-if="moveTreeMenu"
                    @move-folder="handleMoveFolder"
                    :folderid="data.id"
                    :folderdata="data"
                    v-bind="$attrs"
                    v-on="$listeners"
                  ></move-folder-tree-menu>
                </div>
                <div class="right-project-item-menu-modal-item" @click="rename">
                  <div class="right-project-item-menu-modal-item-left">
                    <img
                      src="https://image.xuexiwangzhe.com/Fk9yaeKty6nigT0kvliXM7_2o_-Q"
                      class="right-project-item-menu-modal-item-left-img"
                    />
                    <img
                      src="https://image.xuexiwangzhe.com/Fgzg9YhltSa7b8nnd0hjvWnJrDal"
                      class="right-project-item-menu-modal-item-left-img-actived"
                    />
                    <div>重命名</div>
                  </div>
                </div>
                <div
                  class="right-project-item-menu-modal-item"
                  @click="deleteFolder"
                >
                  <div class="right-project-item-menu-modal-item-left">
                    <img
                      src="https://image.xuexiwangzhe.com/Fp4i_Wbd9xaO35QI4THWrl34MtYl"
                      class="right-project-item-menu-modal-item-left-img"
                    />
                    <img
                      src="https://image.xuexiwangzhe.com/FpC9Dqj7VQZoiYAqe0cnOVoPPynJ"
                      class="right-project-item-menu-modal-item-left-img-actived"
                    />
                    <div>删除</div>
                  </div>
                </div>
                <div class="right-project-item-menu-modal-item">
                  <div class="right-project-item-menu-modal-item-left">
                    <img
                      src="https://image.xuexiwangzhe.com/FsGJUJeYTKKIQTEpSWo4lwXK0rAg"
                      class="right-project-item-menu-modal-item-left-img"
                    />
                    <img
                      src="https://image.xuexiwangzhe.com/Fl595ZHrzRBMkDbaHsI7WuVixu6i"
                      class="right-project-item-menu-modal-item-left-img-actived"
                    />
                    <div>批量管理</div>
                  </div>
                </div>
              </div>
              <div v-else>
                <div
                  class="right-project-item-menu-modal-item"
                  @click="restore"
                >
                  <div class="right-project-item-menu-modal-item-left">
                    <img
                      src="http://image.xuexiwangzhe.com/Fj0PdcBgHLvi2PA_V53XHto-BSGT"
                      class="right-project-item-menu-modal-item-left-img"
                    />
                    <img
                      src="http://image.xuexiwangzhe.com/FqmTkVzVspqmwT_fmMlQTFjNiHW8"
                      class="right-project-item-menu-modal-item-left-img-actived"
                    />
                    <div>还原</div>
                  </div>
                </div>
                <div
                  class="right-project-item-menu-modal-item"
                  @click="deleteLongFolder"
                >
                  <div class="right-project-item-menu-modal-item-left">
                    <img
                      src="http://image.xuexiwangzhe.com/Fp4i_Wbd9xaO35QI4THWrl34MtYl"
                      class="right-project-item-menu-modal-item-left-img"
                    />
                    <img
                      src="https://image.xuexiwangzhe.com/FpC9Dqj7VQZoiYAqe0cnOVoPPynJ"
                      class="right-project-item-menu-modal-item-left-img-actived"
                    />
                    <div>永久删除</div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="right-project-item-bottom">
          <div class="right-project-item-bottom-left">
            <div class="right-project-item-folder-count" v-if="navActived !== 'recycle'">
              <span class="right-project-item-folder-count-number">{{data.projectNum || 0}}</span>
              项目
            </div>
            <div class="right-project-item-folder-count" v-else>
              还有 {{data.deleteDayNum}} 天将永久删除
            </div>
          </div>
        </div>
        <div
          class="right-project-item-folder-batch-mask"
          v-if="batch"
          @click="checkedToggle"
        >
          <img
            class="right-project-item-folder-batch-img"
            src="https://image.xuexiwangzhe.com/FllNb5wd_Wf5RScGO2NyAaPqfoi_"
            v-if="!checkedControl"
          />
          <img
            class="right-project-item-folder-batch-img"
            v-else
            src="https://image.xuexiwangzhe.com/FvFF_I4OTn8Ijcjz-xTkkqfkgXAO"
          />
        </div>
      </div>
    </div>
    <mu-dialog
      :esc-press-close="false"
      :overlay-close="false"
      :open.sync="editModal"
      width="492"
      dialog-class="project-custom-modal project-edit-modal"
    >
      <div class="project-custom-modal-top">
        <div class="project-custom-modal-title">重命名</div>
        <img
          class="project-custom-modal-close-img"
          src="https://image.xuexiwangzhe.com/Fnbsz2MJvhTRZ29k39oGf9_4Ao6c"
          @click="editModal = false"
        />
      </div>
      <mu-text-field class="mu-input" v-model="editName"></mu-text-field>
      <div class="project-custom-modal-btn-box">
        <mu-button
          class="project-custom-modal-btn-cancel"
          @click="editModal = false"
          >取消</mu-button
        >
        <mu-button
          :disabled="!editName"
          @click="renameConfirm"
          class="project-custom-modal-btn-confirm"
          >确定</mu-button
        >
      </div>
    </mu-dialog>
    <mu-dialog
      :esc-press-close="false"
      :overlay-close="false"
      :open.sync="deleteModal"
      width="492"
      dialog-class="project-custom-modal project-delete-modal"
    >
      <div class="project-custom-modal-top">
        <div class="project-custom-modal-title">确认删除</div>
        <img
          class="project-custom-modal-close-img"
          src="https://image.xuexiwangzhe.com/Fnbsz2MJvhTRZ29k39oGf9_4Ao6c"
          @click="deleteModal = false"
        />
      </div>
      <div class="content">
        <div>
          确认删除<span class="content-name">“{{ deleteName }}”</span>吗？
        </div>
        <div>删除后，将在回收站中保留30天，之后将永久删除。</div>
      </div>
      <div class="project-custom-modal-btn-box">
        <mu-button
          class="project-custom-modal-btn-cancel"
          @click="deleteModal = false"
          >取消</mu-button
        >
        <mu-button
          @click="deleteFolderConfirm"
          class="project-custom-modal-btn-confirm confirm-btn"
          >确认删除</mu-button
        >
      </div>
    </mu-dialog>
    <mu-dialog
      :esc-press-close="false"
      :overlay-close="false"
      :open.sync="deleteLongModal"
      width="492"
      dialog-class="project-custom-modal project-delete-modal"
    >
      <div class="project-custom-modal-top">
        <div class="project-custom-modal-title">确认永久删除</div>
        <img
          class="project-custom-modal-close-img"
          src="https://image.xuexiwangzhe.com/Fnbsz2MJvhTRZ29k39oGf9_4Ao6c"
          @click="deleteLongModal = false"
        />
      </div>
      <div class="content">
        <div>
          确认永久删除<span class="content-name">“{{ deleteLongName }}”</span
          >吗？
        </div>
        <div>删除后无法找回。</div>
      </div>
      <div class="project-custom-modal-btn-box">
        <mu-button
          class="project-custom-modal-btn-cancel"
          @click="deleteLongModal = false"
          >取消</mu-button
        >
        <mu-button
          @click="permanentlyDelete"
          class="project-custom-modal-btn-confirm confirm-btn"
          >确认删除</mu-button
        >
      </div>
    </mu-dialog>
  </div>
</template>

<script>
import moveFolderTreeMenu from "./moveFolderTreeMenu";
import { mapState } from "vuex";
export default {
  props: {
    checked: Boolean, // 是否选中
    batch: Boolean, // 批量管理
    data: Object, // 数据
    index: Number, // 数据索引
    navActived: {
      // 是否选中的回收站
      type: String,
      default: "",
    },
  },
  data() {
    return {
      editModal: false,
      deleteModal: false,
      editName: "",
      deleteName: "",
      deleteLongName: "",
      moveTreeMenu: false,
      menuModalShow: false,
      deleteLongModal: false, // 永久删除弹框
    };
  },
  inheritAttrs: false, // 取消props自应用html属性的功能
  computed: {
    checkedControl: {
      set(val) {
        this.$emit("update:checked", val);
      },
      get() {
        return this.checked;
      },
    },
    ...mapState(["listOperateData", "listOperate"]),
  },
  watch: {
    listOperateData: {
      handler: function(newVal, oldVal) {
        if (this.data.id == newVal.id) {
          if (this.listOperate == "rename-folder") {
            this.data.name = newVal.name;
          }
          this.$forceUpdate();
        }
      },
      deep: true,
    },
  },
  components: {
    moveFolderTreeMenu,
  },
  methods: {
    checkedToggle() {
      if (!this.checkedControl) {
        this.checkedControl = true;
      } else {
        this.checkedControl = false;
      }
    },
    closeMenuModal() {
      this.menuModalShow = false;
    },
    rename() {
      this.editName = this.data.name;
      this.editModal = true;
    },
    renameConfirm() {
      this.$axios
        .post("/folder/update", {
          id: this.data.id,
          name: this.editName,
        })
        .then((res) => {
          if (res.success) {
            this.editModal = false;
            this.$emit("edit-folder");
            this.data.name = this.editName;
            this.$store.commit("setListOperate", "rename-folder");
            this.$store.commit("setListOperateData", {
              id: this.data.id,
              name: this.editName,
            });
            this.$message.success("修改成功");
          }
        });
    },
    deleteFolder() {
      this.deleteName = this.data.name;
      this.deleteModal = true;
    },
    deleteLongFolder() {
      this.deleteLongName = this.data.name;
      this.deleteLongModal = true;
    },
    deleteFolderConfirm() {
      this.$axios.post("/folder/delete", { id: this.data.id }).then((res) => {
        if (res.success) {
          this.deleteModal = false;
          this.$emit("delete-folder", this.index);
          this.$store.commit("setListOperate", "delete-folder");
          this.$store.commit("setListOperateData", {
            id: this.data.id,
          });
          this.$message.success("删除成功");
        }
      });
    },
    handleMoveFolder() {
      this.moveTreeMenu = false;
      this.menuModalShow = false;
    },
    // 还原
    restore() {
      this.$axios
        .post("/recycle/restore", {
          id: this.data.id,
          type: 1,
        })
        .then((res) => {
          if (res.success) {
            this.$message.success("还原成功");
            this.$emit("restore-folder", this.index);
          }
        });
    },
    // 永久删除
    permanentlyDelete() {
      this.$axios
        .post("/recycle/permanentlyDelete", {
          id: this.data.id,
          type: 1,
        })
        .then((res) => {
          if (res.success) {
            this.$message.success("删除成功");
            this.$emit("permanentlydelete-folder", this.index);
          }
        });
    },
  },
};
</script>

<style lang="less">
.project-custom-modal {
  border-radius: 18px !important;
  padding: 30px !important;

  .mu-dialog-body {
    padding: 0;
  }
}

.project-custom-modal-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 26px;
}

.project-custom-modal-title {
  font-size: 20px;
  color: #333;
  font-weight: bold;
}

.project-custom-modal-close-img {
  width: 14px;
  cursor: pointer;
}

.project-custom-modal-btn-box {
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.project-custom-modal-btn-cancel {
  border-radius: 15px !important;
  border: 1px solid #666666 !important;
  width: 120px !important;
  height: 30px !important;
  box-shadow: none !important;
  font-size: 12px !important;
  color: #666 !important;
  font-weight: bold;
  margin-right: 21px !important;
}

.project-custom-modal-btn-confirm {
  width: 120px !important;
  height: 30px !important;
  background: #265cff !important;
  color: #fff !important;
  font-weight: bold;
  border-radius: 17px !important;
  box-shadow: none !important;
  font-size: 12px !important;
}

.project-edit-modal {
  .mu-input {
    width: 100%;
    margin-bottom: 65px;
  }
}

.project-delete-modal {
  .content {
    color: #333;
    font-size: 15px;
    margin-bottom: 50px;
    text-align: left;
  }

  .content-name {
    font-weight: bold;
  }

  .confirm-btn {
    background-color: #ff7632 !important;
  }
}

.right-project-item {
  position: relative;
  width: 263px;
  box-sizing: border-box;
  height: 129px;
  flex-shrink: 0;
  margin-right: 26px;
  margin-bottom: 25px;
  padding: 17px 16px 20px 30px;
  background: #ffffff;
  border-radius: 11px;
}

.right-project-item-box:nth-child(3n + 3) {
  .right-project-item {
    margin-right: 0;
  }
}

@media screen and (min-width: 1420px) {
  .right-project-item-box:nth-child(3n + 3) {
    .right-project-item {
      margin-right: 26px;
    }
  }
  .right-project-item-box:nth-child(4n + 4) {
    .right-project-item {
      margin-right: 0;
    }
  }
}

@media screen and (min-width: 1920px) {
  .right-project-item-box:nth-child(4n + 4) {
    .right-project-item {
      margin-right: 26px;
    }
  }

  .right-project-item-box:nth-child(5n + 5) {
    .right-project-item {
      margin-right: 0;
    }
  }
}

.right-project-item-folder {
  padding: 0;
  background-color: transparent;
}

.right-project-item-folder-top-img {
  width: 75px;
  display: block;
}

.right-project-item-folder-top-batch-img {
  opacity: 0.5;
}

.right-project-item-folder-main {
  padding: 12px 12px 15px 21px;
  height: 113px;
  background: #c9d6ff;
  border-radius: 0px 11px 11px 11px;
  position: relative;
}

.right-project-item-folder-batch-mask {
  cursor: pointer;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(51, 51, 51, 0.5);
  border-radius: 0px 11px 11px 11px;
}

.right-project-item-folder-batch-img {
  width: 30px;
}

.right-project-item-folder-main-top {
  margin-bottom: 40px !important;
}

.right-project-item-folder-count {
  color: #333;
}

.right-project-item-folder-count-number {
  margin-right: 5px;
}

.right-project-item-folder-title {
  margin-bottom: 0 !important;
}

.right-project-item-sign {
  position: absolute;
  top: 0;
  left: 0;
  width: 12px;
  height: 100%;
  background: #fdad3f;
  border-radius: 11px 0px 0px 11px;
}

.right-project-item-top {
  display: flex;
  justify-content: space-between;
  margin-bottom: 19px;
}

.right-project-item-operate {
  display: flex;
  align-items: flex-start;
}

.right-project-item-operate-img {
  &:last-child {
    margin-right: 0;
  }
  width: 18px;
  margin-right: 9px;
}

.right-project-item-title {
  font-size: 16px;
  color: #333;
  font-weight: bold;
  margin-bottom: 5px;
}

.right-project-item-share-img {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

.right-project-item-menu-box {
  position: relative;
}

.right-project-item-menu-modal {
  position: absolute;
  z-index: 10;
  top: 24px;
  left: -23px;
  background: #ffffff;
  box-shadow: 0px 2px 6px 0px rgba(102, 102, 102, 0.2);
  border-radius: 3px;
}

.right-project-item-menu-modal-item {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-left: 15px;
  padding-right: 5px;
  padding-top: 6px;
  padding-bottom: 6px;
  width: 116px;
  box-sizing: border-box;
  margin-bottom: 6px;
  color: #666;
  cursor: pointer;

  .right-project-item-menu-modal-item-right-img {
    width: 12px;
  }

  .right-project-item-menu-modal-item-right-img-actived {
    width: 12px;
    display: none;
  }

  .right-project-item-menu-modal-item-left-img {
    width: 12px;
    margin-right: 9px;
  }

  .right-project-item-menu-modal-item-left-img-actived {
    width: 12px;
    margin-right: 9px;
    display: none;
  }

  &:last-child {
    margin-bottom: 0;
  }

  &:hover {
    background-color: #999999;
    color: #fff;

    .right-project-item-menu-modal-item-right-img {
      display: none;
    }

    .right-project-item-menu-modal-item-right-img-actived {
      display: block;
    }

    .right-project-item-menu-modal-item-left-img {
      display: none;
    }

    .right-project-item-menu-modal-item-left-img-actived {
      display: block;
    }
  }
}

.right-project-item-menu-modal-item-left {
  display: flex;
  align-items: center;
}

.right-project-item-menu-modal-item-right-img {
  width: 12px;
}

.right-project-item-time {
  color: #999999;
}

.right-project-item-bottom {
  display: flex;
  justify-content: space-between;
}

.right-project-item-bottom-left {
  display: flex;
  align-items: center;
}

.right-project-item-tag {
  width: 48px;
  height: 24px;
  text-align: center;
  line-height: 24px;
  background: #f2f4f8;
  border-radius: 12px;
  color: #333;
  font-size: 11px;
  margin-right: 8px;
}

.right-project-item-count {
  color: #333;
  font-size: 12px;
}

.right-project-item-count-number {
  font-weight: bold;
  margin-right: 2px;
}

.right-project-item-collect-img {
  width: 18px;
  height: 18px;
}
</style>
